package com.itany.corejava.day12;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestCount {

    private JFrame jf;
    private JLabel jl;
    private JButton jb1;
    private JButton jb2;

    private int count=0;

    public TestCount() {
        jf=new JFrame();
        jl=new JLabel(count+"");
        jb1=new JButton("+");
        jb2=new JButton("-");
    }

    private void init(){
        jf.setLayout(new FlowLayout());
        jf.add(jl);
        jf.add(jb1);
        jf.add(jb2);
    }

    private void addEventHandler(){
//        jb1.addActionListener(new AddActionListener());
//        jb2.addActionListener(new SubActionListener());

//        jb1.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("+");
//                jl.setText(++count+"");
//            }
//        });
//
//        jb2.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("-");
//                jl.setText(--count+"");
//            }
//        });


        jb1.addActionListener(e->{
            System.out.println("+");
            jl.setText(++count+"");
        });

        jb2.addActionListener(e->{
            System.out.println("-");
            jl.setText(--count+"");
        });

    }


    public void show(){
        init();
        addEventHandler();
        jf.pack();
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new TestCount().show();
    }


}
